function main(defaultParams) {
    debugger
    // 状态码说明：
    // 1    申请中
    // 2    制证中
    // 3    已发证
    // 4    注销中

    // cardStateCode 与 approval_type 的对应关系：
    // cardStateCode = 1  ==> approval_type = 1 (申请)
    // cardStateCode = 5  ==> approval_type = 2 (变更)
    // cardStateCode = 4  ==> approval_type = 3 (注销)

    let cardStateCode = defaultParams.card_state_code.value

    const self = this;
    if (defaultParams.callbackParams) {
        var validFlag = defaultParams.callbackParams.data.root_8hq6z0.radio_4bwikf;
        var confiscatedCardInfoId = defaultParams.callbackParams.data.root_8hq6z0.number_input_bo160u;
        let stateCode = 2;
        let approvalStateCode = 3;

        // 根据 cardStateCode 确定审批类型
        let approvalType = getApprovalTypeByCardState(cardStateCode);

        // 审核通过逻辑
        if (validFlag === '1') {
            stateCode = 3;
            approvalStateCode = 3;
            let approvalDate = {
                confiscatedCardId: confiscatedCardInfoId,
                unitId: '1',
                unitName: '宁夏回族自治区',
                humanId: '30062',
                humanName: '王娟',
                approvalStateCode: "0",
                approvalType: approvalType,
                stageId: 3,
                stageName: "终审",
                opinion: ""
            }
            // 新增终审记录
            insertLawConfiscatedCardApprovalInfo(approvalDate).then(res => {
                console.log("终审记录插入成功");
            });
        } else {
            // 审核不通过逻辑
            stateCode = 1;
            approvalStateCode = 2;
        }

        // 更新主表状态
        var id = defaultParams.callbackParams.data.root_8hq6z0.number_input_bo160u;
        var update = "UPDATE('ds_tbl:t_78e3820cec034204b3ec0f507253f5de',QUERY_EQ('id'," + id + "),'', ['state_code'," + stateCode + ",'approval_state_code','" + approvalStateCode + "'])";

        api.EXEC_FORMULA(update).then((res) => {
            console.log("状态更新成功");
            // 刷新相关列表组件
            refreshListComponents(self);
        }).catch(err => {
            console.error("状态更新失败:", err);
        });
    }
}

/**
 * 根据cardStateCode获取对应的审批类型
 * @param {number} cardStateCode
 * @returns {string} 审批类型
 */
function getApprovalTypeByCardState(cardStateCode) {
    const code = parseInt(cardStateCode);

    switch(code) {
        case 1:
            return "1"; // 申请
        case 5:
            return "2"; // 变更
        case 4:
            return "3"; // 注销
        default:
            return "1"; // 默认申请类型
    }
}

/**
 * 刷新列表组件
 * @param {object} self 当前组件实例
 */
function refreshListComponents(self) {
    let pageListEle = self.$$("page_widget_list_7b6w07");
    if (pageListEle) {
        let listRenderView = pageListEle.$$getRenderElement();
        let currentListEle = listRenderView.$$getListElement();
        currentListEle.$$refreshData();
    }
    let pageListEle1 = self.$$("page_widget_list_4gydhm");
    if (pageListEle1) {
        let listRenderView1 = pageListEle1.$$getRenderElement();
        let currentListEle1 = listRenderView1.$$getListElement();
        currentListEle1.$$refreshData();
    }
}

/**
 * 插入罚没证审批信息
 * @param {object} approvalData 审批数据
 * @returns {Promise}
 */
function insertLawConfiscatedCardApprovalInfo(approvalData) {
    const insertLawConfiscatedCardApprovalInfoSql = [
        ['confiscated_card_id', approvalData.confiscatedCardId],
        ['unit_id', "'" + approvalData.unitId + "'"],
        ['unit_name', "'" + approvalData.unitName + "'"],
        ['human_id', "'" + approvalData.humanId + "'"],
        ['human_name', "'" + approvalData.humanName + "'"],
        ['approval_state_code', "'" + approvalData.approvalStateCode + "'"],
        ['opinion', "'" + approvalData.opinion + "'"],
        ['approval_type', "'" + approvalData.approvalType + "'"],
        ['STAGE_ID', "'" + approvalData.stageId + "'"],
        ['STAGE_NAME', "'" + approvalData.stageName + "'"],
        ['approval_time', 'NOW()']
    ];

    let law_confiscated_card_approval_info = 'ds_tbl:t_d6d40a9fbcac40568e164e9976b35459';

    // 构建参数化INSERT语句
    const formattedFields = insertLawConfiscatedCardApprovalInfoSql.map(function (field) {
        return "'" + field[0] + "'," + field[1];
    });

    const insertSql = "INSERT('" + law_confiscated_card_approval_info + "', [" + formattedFields.join(',') + "])";
    console.log("准备执行的SQL语句:", insertSql);

    return new Promise(function (resolve, reject) {
        api.EXEC_FORMULA(insertSql)
            .then(function (res) {
                console.log("审批记录插入成功");
                resolve(res);
            })
            .catch(function (err) {
                console.error("审批记录插入失败:", err);
                reject(new Error(`审批记录插入失败: ${err.message}`));
            });
    });
}
